<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <style>
        html,body{
            height: 100%;
        }
        body{
            margin: 0;
            background-color: pink;
            overflow: hidden;
            color: white;
        }
        header{
            width: 700px;
            margin: 10px auto;
        }
        li{
            width: 20px;
            height: 20px;
            display: inline-block;
            position: relative;
            cursor: pointer;
        }
        .l1{
            background-color: red;
        }
        .l2{
            background-color: green;
        }
        .l3{
            background-color: black;
        }
        main{
            width: 700px;
            margin: 0 auto;
            text-align: center;
        }
        main div{
            display: inline-block;
            width: 100px;
            height: 30px;
            border:1px solid white;
            line-height: 30px;
            text-align: center;
            margin: 0;
            float: left;
            background-color: red;
        }
        .active{
            display: inline-block;
            position: absolute;
            width: 10px;
            height: 10px;
            background-color: white;
            left: 5px;
            top: 5px;
        }
    </style>
</head>
<body>
    <header>
        <li class="l1"><span class="active"></span></li>
        <li class="l2"><span></span></li>
        <li class="l3"><span></span></li>
    </header>
    <main>
        <div>新闻</div>
        <div>娱乐</div>
        <div>体育</div>
        <div>电影</div>
        <div>音乐</div>
        <div>旅游</div>
    </main>
</body>
</html>
<script>
    var lis  = document.querySelectorAll('li');
    var spans = document.querySelectorAll('span');
    var divs = document.querySelectorAll('div');
    var body = document.body;
    for(var i=0;i<lis.length;i++){
        lis[i].index=i;
        lis[i].onclick = function(){
            console.log(this.index);
            for(var j=0;j<spans.length;j++){
                spans[j].className='';
            }
            if(this.index==0){
                spans[0].className='active';
                body.style.backgroundColor='pink';
                for(var i=0;i<divs.length;i++){
                    divs[i].style.backgroundColor='red';
                }
            }
            if(this.index==1){
                spans[1].className='active';
                body.style.backgroundColor='blue';
                 for(var i=0;i<divs.length;i++){
                    divs[i].style.backgroundColor='green';
                }
            }
            if(this.index==2){
                spans[2].className='active';
                body.style.backgroundColor='gray';
                 for(var i=0;i<divs.length;i++){
                    divs[i].style.backgroundColor='black';
                }
            }
            
        }
    }
</script>